{extend name="adminblue/base" /}
{block name="resources"/}
<link href="ADMIN_CSS/express/freight_edit.css" rel="stylesheet" type="text/css" />
<link href="ADMIN_CSS/serviceSet.css" rel="stylesheet" type="text/css" />
{/block}
{block name="main"}
<div class="mod-table">
	<div class="table-div">
		<table>
			<tbody>
				<tr>
					<td colspan="2" class="back-f5f5f5">
						<div class="table-title-font">
							<span>客服中心</span>
						</div>
					</td>
				</tr>
				<tr>
					<td class="table-1td">售前客服</td>
					<td>
						<div class="controls">
							<ul class="pre-sales">
								<li>客服名称</li>
								<li>客服工具</li>
								<li>客服账号</li>
							</ul>
							{foreach name="pre_data" id="v"}
								<ul class="pre-content pre_container" data-num="1">
								<li><input type="text" value="{$v['pre_name']}" id="pre_name" ></li>
								<li>
									<select name="" id="pre_tool">
										<option value="1" {if condition="$v['pre_tool'] == 1"}selected="selected"{/if}>QQ</option>
										<!-- <option value="2" {if condition="$v['pre_tool'] == 2"}selected="selected"{/if}>旺旺</option> -->
									</select>
								</li>
								<li><input type="text" value="{$v['pre_account']}" id="pre_account" placeholder="请输入客服账号"></li>
								<li><button class="btn-common btn-del" onclick="del_info(this)">删除</button>
								</li>
								</ul>
								
							{/foreach}
							{empty name="pre_data"}
									<ul class="pre-content pre_container" data-num="1">
								<li><input type="text" value="售前1" id="pre_name" ></li>
								<li><select name="" id="pre_tool">
										<option value="0">请选择工具</option>
										<option value="1" selected>QQ</option>
										<!-- <option value="2">旺旺</option> -->
									</select>
								</li>
								<li><input type="text" value="" id="pre_account" placeholder="请输入客服账号"></li>
								<li><button class="btn-common btn-del" onclick="del_info(this)">删除</button>
								</li>
								</ul>
								{/empty}
							<a class="btn-gradient-blue pre_add" onclick="add_html(1,this)" href="javascript:;" style="margin-left: 2.5%;"><b>+</b>添加客服</a>
						</div>
					</td>
				</tr>
				<tr>
					<td class="table-1td">售后客服</td>
					<td>
						<div class="controls">
							<ul class="pre-sales">
								<li>客服名称</li>
								<li>客服工具</li>
								<li>客服账号</li>
							</ul>
							{foreach name="after_data" id="v"}
								<ul class="pre-content after_container" data-num="1">
								<li><input type="text" value="{$v['after_name']}" id="after_name"></li>
								<li>
									<select name="" id="after_tool">
										<option value="1" {if condition="$v['after_tool'] == 1"}selected="selected"{/if}>QQ</option>
										<!-- <option value="2" {if condition="$v['after_tool'] == 2"}selected="selected"{/if}>旺旺</option> -->
									</select>
								</li>
								<li><input type="text" value="{$v['after_account']}" id="after_account" placeholder="请输入客服账号"></li>
								<li><button class="btn-common btn-del" onclick="del_info(this)">删除</button>
								</li>
								</ul>
							{/foreach}
							{empty name="after_data"}
							<ul class="pre-content after_container" data-num="1">
								<li><input type="text" value="售后1" id="after_name"></li>
								<li><select name="" id="after_tool">
										<option value="0">请选择工具</option>
										<option value="1" selected>QQ</option>
										<!-- <option value="2">旺旺</option> -->
									</select>
								</li>
								<li><input type="text" value="" id="after_account" placeholder="请输入客服账号"></li>
								<li><button class="btn-common btn-del" onclick="del_info(this)">删除</button></li>
							</ul>
							{/empty}
							<a class="btn-gradient-blue after_add" onclick="add_html(2,this)" href="javascript:;" style="margin-left: 2.5%;"><b>+</b>添加客服</a>
						</div>
					</td>
				</tr>
				<tr>
					<td class="table-1td">工作时间</td>
					<td>
						<div class="work_title">
							<span>例：（工作时间 AM 10:00 - PM 18:00）</span>
						</div>
						<div class="work_time">
							<textarea name="work_time" id="work_time" cols="30" rows="10">{$work_time}</textarea>
						</div>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
	<p class="mt60" style="text-align: center;width:80%;">
		<button class="btn-common btn-big" onclick="save_service()">保存</button>
	</p>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
window.onload=function(){
	var is_open = $("#is_open").val();
	if(parseInt(is_open) == 0){
		$("#manebaoyouResultNo").prop("checked","checked");
	}else{
		$("#manebaoyouResultYes").prop("checked","checked");
	}
};
function add_html(type,e){
	//1.售前 2.售后
	if(type == 1){
		var prefix = 'pre_';
		var container = 'pre_container';
		var data_num = $("."+container).length + 1;
		var name = '售前'+data_num+'';
	}else{
		var prefix = 'after_';
		var container = 'after_container';
		var data_num = $("."+container).length + 1;
		var name = '售后'+data_num+'';
	}
	var add_html = '';
		
		add_html += '<ul class="pre-content '+container+'" data-num="'+data_num+'">';
		add_html += '<li><input type="text" value="'+name+'" id="'+prefix+'name"></li>\n';
/* 		add_html += '<li><select name="" id="'+prefix+'tool"><option value="0">请选择工具</option><option value="1">QQ</option><option value="2">旺旺</option></select></li>\n'; */
		add_html += '<li><select name="" id="'+prefix+'tool"><option value="0">请选择工具</option><option value="1">QQ</option></select></li>\n';
		add_html += '<li><input type="text" value="" id="'+prefix+'account" placeholder="请输入客服账号"></li>\n';
		add_html += '<li><button class="btn-common btn-del" onclick="del_info(this)">删除</button></li>';
		add_html += '</ul>';
	$(e).before(add_html);
}
function SavepointConfig(){
	setProvinceIdArray();
	setCityIdArray();
	var is_open = $("input[type='radio'][name='fare']:checked").val();
	var full_mail_money = $("#full_mail_money").val();
	if(full_mail_money == ''){
		$("#full_mail").show();
		return false;
	}
	var no_mail_province_id_array = $("#hidden_province_id_array").val();
	var no_mail_city_id_array = $("#hidden_city_id_array").val();
	$.ajax({
		type:"post",
		url : "{:__URL('ADMIN_MAIN/promotion/fullshipping')}",
		data : {
			"is_open" : is_open,
			"full_mail_money" : full_mail_money,
			"no_mail_province_id_array" : no_mail_province_id_array, 
			"no_mail_city_id_array" : no_mail_city_id_array
		},
		success : function(data){
			if(data['code'] > 0){
				showMessage('success', data["message"]);
			}else{
				showMessage('error', data["message"]);
			}
		}
	});
}
function save_service()
{	
	//售前 pre
	var pre_array = new Array();
	for (var i = 1; i <= $(".pre_container").length; i++ ) {
		j = i-1;
		pre = new Object();
		pre.pre_name = $(".pre_container").eq(j).children().children("#pre_name").val();
		pre.pre_tool = $(".pre_container").eq(j).children().children("#pre_tool").val();
		pre.pre_account = $(".pre_container").eq(j).children().children("#pre_account").val();
		if(pre.pre_name != '' && pre.pre_tool != 0 && pre.pre_account != ''){
			pre_array[j] = pre;
		}
		
	}
	
	//售后
	var after_array = new Array();
	for (var i = 1; i <= $(".after_container").length; i++ ) {
		j = i-1;
		after = new Object();
		after.after_name = $(".after_container").eq(j).children().children("#after_name").val();
		after.after_tool = $(".after_container").eq(j).children().children("#after_tool").val();
		after.after_account = $(".after_container").eq(j).children().children("#after_account").val();
		if(after.after_name != '' && after.after_tool != 0 && after.after_account != ''){
			after_array[j] = after;
		}
	}
	//工作时间
	var work_time = $("#work_time").val();
	$.ajax({
		url : "{:__URL('ADMIN_MAIN/shop/serviceSet')}",
		type:'post',
		data:{'pre':JSON.stringify(pre_array),'after':JSON.stringify(after_array),'work_time':work_time},
		success : function(res){
			if(res>0){
				showMessage('success', '保存成功', 'ADMIN_MAIN/shop/serviceset');
			}else{
				showMessage('error', '保存失败');
			}
		}
	})
}
function del_info(e){
	$(e).parent().parent().remove();
}
</script>
<script src="ADMIN_JS/selectNoMailArea.js"></script>
{/block}